<?php
// +----------------------------------------------------------------------
// | Diygw PHP
// +----------------------------------------------------------------------
// | Copyright (c) 2022~2024 https://www.diygw.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: diygw <diygwcom@diygw.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\shop\model;

use diygw\model\DiygwModel;

/**
 * @package app\shop\model
 */
class AddressModel extends DiygwModel
{
    // 表名
    public $name = 'shop_address';

    // 相似查询字段
    protected $likeField=[];

    public function afterAdd(&$data)
    {
        //如果是默认地址，请空其他所有的默认地址
        if($data['isdefault']=='1'){
            $addressModel = new AddressModel();
            $addressModel->where('id','<>',$data['id'])->where('isdefault','1')->update(['isdefault'=>'2']);
        }
    }

    public function afterEdit(&$data)
    {
        //如果是默认地址，请空其他所有的默认地址
        if($data['isdefault']=='1'){
            $addressModel = new AddressModel();
            $addressModel->where('id','<>',$data['id'])->where('isdefault','1')->update(['isdefault'=>'2']);
        }
    }
}
